﻿using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.ApiExplorer;
using System;
using static LogForParameter.Api.SwaggerHelp.CustomApiVersion;

namespace LogForParameter.Api.SwaggerHelp
{
    [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
    public class CustomRouteAttribute : RouteAttribute, IApiDescriptionGroupNameProvider, IApiDescriptionVisibilityProvider
    {
        /// <summary>
        /// 继承routeAttribute的基类自定义构造函数
        /// </summary>
        /// <param name="actionName"></param>
        public CustomRouteAttribute(string actionName = "[action]") :
            base("/api/{version}/{controller}" + actionName)
        {

        }
        /// <summary>
        /// 定义版本号和路由构造函数，继承基类路由
        /// </summary>
        /// <param name="version">版本号</param>
        /// <param name="actionName">接口名方法名称</param>
        public CustomRouteAttribute(MyApiVersion version, string actionName = "[action]") : base($"/api/{version}/[controller]/{actionName}")
        {
            GroupName = version.ToString();
        }
        /// <summary>
        /// 版本组号
        /// </summary>
        public string GroupName { get; set; }
        /// <summary>
        /// 是否隐藏
        /// </summary>
        public bool IgnoreApi { get; set; }
    }
}
